import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '@/pages/Home.vue'
import {useUserStore} from '@/stores/modules/user'
import { close, start } from '@/nprogress/nprogress';
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      component: HomeView,
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/pages/Login.vue'),
    },
    {
      path: '/feedback',
      name: 'feedback',
      component: () => import('@/pages/Feedback.vue'),
    },
  ],
})

//路由控制
router.beforeEach((to,form,next)=>{
  start()
  let userStore=useUserStore()
  if(userStore.userinfo==null&&to.path!="/feedback"){
      if(to.path!="/login"){
          next({name:"login"})
      }
      else{
          next()
      }
  }else{
      next()
  }
})
router.afterEach(() => {
	close();
})

export default router
